﻿using System.Linq;
using cfg.card;
using cfg.character;
using cfg.pawn;
using kemocard.Scripts.Common;
using kemocard.Scripts.Module.Battle;
using kemocard.Scripts.Pawn;

namespace kemocard.Scripts.Hero;

public class Chalux : HeroScript
{
    public override string GetDesc()
    {
        return "冷却：4。消耗75点能量,自身/2回合/物理攻击提高25000";
    }

    public override void UseSkill(BattleCharacter parent, int skillIdx = 0)
    {
        if (skillIdx != 1) return;
        var buff = StaticUtil.NewBuffOrNullById("CHALUX_SKILL_BUFF", parent);
        if (buff == null) return;
        parent.AddBuff(buff);
    }

    public Chalux()
    {
        SkillCoolDown = [4];
        SkillPowerCost = [75];
    }
}

public class Merlin : HeroScript
{
    public override string GetDesc()
    {
        return "冷却：3。消耗65能量，己方/全体/2回合/全攻击提升10000";
    }

    public override void UseSkill(BattleCharacter parent, int skillIdx = 0)
    {
        if (skillIdx != 1) return;
        var buff = StaticUtil.NewBuffOrNullById("MERLIN_SKILL_BUFF", parent);
        if (buff == null) return;
        Mod?.Teammates.ForEach(c => c.AddBuff(buff));
    }

    public Merlin()
    {
        SkillCoolDown = [3];
        SkillPowerCost = [65];
    }
}

public class Forge : HeroScript
{
    public override string GetDesc()
    {
        return "冷却：5。消耗75点能量，敌方/全体/物理/200%物理攻击火属性伤害,己方/全体/2回合/全防御提高20%伤害量";
    }

    public override void UseSkill(BattleCharacter parent, int skillIdx = 0)
    {
        if (skillIdx != 1) return;
        Damage damage = new()
        {
            Value = 200 * parent.PAttack,
            Attribute = (int)Attribute.FIRE,
            Role = Role.BLOCKER,
            Tags = [Tag.FIRE, Tag.PATTACK, Tag.AT],
            Times = 1,
            OnHit = OnHit
        };
        Mod?.DoDamage(damage);
    }

    private static void OnHit(Damage arg1, BasePawn arg2, float arg3)
    {
        var buff2 = StaticUtil.NewBuffOrNullById("FORGE_SKILL_BUFF", arg2);
        if (buff2 != null)
        {
            foreach (var pawn in arg1.Target)
            {
                pawn.AddBuff(buff2);
            }
        }

        arg1.OnHit -= OnHit;
    }

    public Forge()
    {
        SkillCoolDown = [5];
        SkillPowerCost = [75];
    }
}

public class Ellis : HeroScript
{
    public override string GetDesc()
    {
        return "冷却：6。消耗80点能量，敌方/全体/魔法/50000 + 500%攻击力暗属性伤害\n" +
               "被动1：进入战斗时，冷却减少3";
    }

    public override void UseSkill(BattleCharacter parent, int skillIdx = 0)
    {
        if (skillIdx != 1) return;
        Damage damage = new()
        {
            Value = 50000 + parent.MAttack * 5,
            Attribute = (int)Attribute.DARK,
            Role = Role.BLOCKER,
            Tags = [Tag.DARK, Tag.AT, Tag.MATTACK],
            Times = 1
        };
        Mod?.DoDamage(damage);
    }

    public Ellis()
    {
        SkillCoolDown = [6];
        SkillPowerCost = [80];
    }

    public override void OnBattleStart()
    {
        Owner.DoCoolDown(3);
    }
}

public class Collin : HeroScript
{
    public override string GetDesc()
    {
        return "冷却：3。消耗60点能量，己方/全体/1回合/生命上限提高50000";
    }

    public override void UseSkill(BattleCharacter parent, int skillIdx = 0)
    {
        if (skillIdx != 1) return;
        var buff = StaticUtil.NewBuffOrNullById("COLLIN_SKILL_BUFF", parent);
        if (buff == null) return;
        Mod?.Teammates.ForEach(c => c.AddBuff(buff));
    }

    public Collin()
    {
        SkillCoolDown = [3];
        SkillPowerCost = [60];
    }
}

public class Star : HeroScript
{
    public override string GetDesc()
    {
        return "冷却：6。消耗75点能量，敌方/全体/物理/800%攻击力光属性伤害\n" +
               "被动1：战斗开始时，冷却减少3";
    }

    public override void UseSkill(BattleCharacter parent, int skillIdx = 0)
    {
        if (skillIdx != 1) return;
        Damage damage = new()
        {
            Value = 800 * parent.PAttack,
            Attribute = (int)Attribute.LIGHT,
            Role = Role.ATTACKER,
            Tags = [Tag.LIGHT, Tag.PATTACK, Tag.AT],
            Times = 1
        };
        Mod?.DoDamage(damage);
    }

    public Star()
    {
        SkillCoolDown = [6];
        SkillPowerCost = [75];
    }
}

public class Seth : HeroScript
{
    public override string GetDesc()
    {
        return "冷却：5。消耗75点能量，己方/全体/1回合/物理攻击提高25000\n" +
               "被动1：战斗开始时，冷却减少3";
    }

    public override void UseSkill(BattleCharacter parent, int skillIdx = 0)
    {
        if (skillIdx != 1) return;
        var buff = StaticUtil.NewBuffOrNullById("SETH_SKILL_BUFF", parent);
        if (buff == null) return;
        Mod?.Teammates.ForEach(c => c.AddBuff(buff));
    }

    public Seth()
    {
        SkillCoolDown = [5];
        SkillPowerCost = [75];
    }
}

public class Rains : HeroScript
{
    public override string GetDesc()
    {
        return "冷却：0。消耗25点能量，敌方/全体/1回合/全攻击降低10000\n" +
               "蓄力Ⅰ:冷却2。消耗50能量，敌方/全体/1回合/全攻击降低10000,受到的攻击+25%最终伤害";
    }

    public override void UseSkill(BattleCharacter parent, int skillIdx = 0)
    {
        switch (skillIdx)
        {
            case 1:
                var buff = StaticUtil.NewBuffOrNullById("RAINS_SKILL_BUFF", parent);
                if (buff == null) return;
                Mod?.Enemies.ForEach(c => c.AddBuff(buff));
                break;
            case 2:
                var buff2 = StaticUtil.NewBuffOrNullById("RAINS_SKILL_BUFF2", parent);
                if (buff2 == null) return;
                Mod?.Enemies.ForEach(c => c.AddBuff(buff2));
                break;
        }
    }

    public Rains()
    {
        SkillCoolDown = [0, 2];
        SkillPowerCost = [25, 50];
    }
}

public class Carter : HeroScript
{
    public override string GetDesc()
    {
        return "冷却3。消耗75点能量，自身/3回合/嘲讽:5,生命上限提高100000";
    }

    public override void UseSkill(BattleCharacter parent, int skillIdx = 0)
    {
        if (skillIdx != 1) return;
        var buff = StaticUtil.NewBuffOrNullById("CARTER_SKILL_BUFF", parent);
        if (buff == null) return;
        parent.AddBuff(buff);
    }

    public Carter()
    {
        SkillCoolDown = [3];
        SkillPowerCost = [75];
    }
}

public class Zeller : HeroScript
{
    public override string GetDesc()
    {
        return "冷却0。消耗15点能量，自身/1回合/物理攻击提高5000";
    }

    public override void UseSkill(BattleCharacter parent, int skillIdx = 0)
    {
        if (skillIdx != 1) return;
        var buff = StaticUtil.NewBuffOrNullById("ZELLER_SKILL_BUFF", parent);
        if (buff == null) return;
        parent.AddBuff(buff);
    }

    public Zeller()
    {
        SkillCoolDown = [0];
        SkillPowerCost = [15];
    }
}

public class Santos : HeroScript
{
    public override string GetDesc()
    {
        return "冷却2。消耗45点能量，敌全体/1回合/全攻击降低7500.光属性的场合，受到的暗属性伤害的最终伤害增加30%";
    }

    public override void UseSkill(BattleCharacter parent, int skillIdx = 0)
    {
        if (skillIdx != 1) return;
        var buff = StaticUtil.NewBuffOrNullById("SANTOS_SKILL_BUFF", parent);
        if (buff == null) return;
        Mod?.Enemies.ForEach(c => c.AddBuff(buff));
    }

    public Santos()
    {
        SkillCoolDown = [2];
        SkillPowerCost = [45];
    }
}

public class Typhoon : HeroScript
{
    public override string GetDesc()
    {
        return "冷却2。消耗50点能量，己方全体/2回合/全攻击提高10000";
    }

    public override void UseSkill(BattleCharacter parent, int skillIdx = 0)
    {
        if (skillIdx != 1) return;
        var buff = StaticUtil.NewBuffOrNullById("TYPHOON_SKILL_BUFF", parent);
        if (buff == null) return;
        Mod?.Teammates.ForEach(c => c.AddBuff(buff));
    }

    public Typhoon()
    {
        SkillCoolDown = [2];
        SkillPowerCost = [50];
    }
}